package cn.lzit.request.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.Arrays;

/**
 * Servlet implementation class ResultServlet
 */


public class ResultServlet extends HttpServlet {
    private static final long serialVersionUID=1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取信息
        String name = request.getParameter("username");
        String pwd = request.getParameter("password");
        String age = request.getParameter("age");
        String sex = request.getParameter("sex");
        String[] loves = request.getParameterValues("loves");
        String email = request.getParameter("email");
        String tel = request.getParameter("tel");
        //解决中文乱码
        response.setContentType("text/html;charset=utf-8");

        //判断密码合规
        PrintWriter pWriter = response.getWriter();
        pWriter.print("<body bgcolor='pink'>");
        if(pwd.length()<6||pwd.length()>10){
            response.sendRedirect("register.html");
        }

        //打印信息
        pWriter.print("用户名:"+name+"<br/>");
        pWriter.print("密码:"+pwd+"<br/>");
        pWriter.print("年龄:"+age+"<br/>");
        pWriter.print("性别:"+sex+"<br/>");
        pWriter.print("爱好:"+ Arrays.toString(loves) +"<br/>");
        pWriter.print("Email:"+email+"<br/>");
        pWriter.print("Tel:"+tel+"<br/>");
        pWriter.print("</body>");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //TODO Auto-generated method stub
        doGet(request, response);
    }
}
